package db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author Admin
 */
public class DBcon  {

    public DBcon() {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/java", "root", "123456");
            System.out.println("соединение установлено");
            Statement s = con.createStatement();
            String sql = "SELECT name, surname FROM users";
            ResultSet rs = s.executeQuery(sql);

            while (rs.next()) {
                System.out.println(rs.getString("name") + " " + rs.getString("surname"));
            }
            rs.close();
            s.close();
            con.close();
        } catch (ClassNotFoundException e1) {
            System.out.println(e1.toString());
        } catch (SQLException e2) {
            System.out.println(e2.toString());
        } catch (Exception e3) {
            System.out.println(e3.toString());
        }
    }
}
